// pages/module/opinion/opinion.js
import regeneratorRuntime from '../../../utils/runtime.js';
import { getData, setData, clearData, dataKey } from '../../../utils/storage.js';
import shareFun from '../../../utils/shareFun.js';
import {
  opinionClass,
  submitOpinion
} from '../../../utils/imapi.js';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    index:0,
    ask_list:[
      {name:'收益类'},
      {name:'违规订单类'},
      {name:'拉新类'},
      {name:'其他常见问题'},
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:async function (options) {
    shareFun.hidenShareMenu();
    const {data} = await opinionClass()
    this.suggestion_type = data[0].id
    this.suggestion_content = ''
    this.setData({
      ask_list:data
    })
  },
  bindPickerChange: function(e) {
    this.suggestion_type = this.data.ask_list[e.detail.value].id
    this.setData({
      index: e.detail.value
    })
  },
  async submit(){
    const {data} = await submitOpinion({suggestion_content:this.suggestion_content,suggestion_type:this.suggestion_type})
    wx.showToast({
      title: '提交成功',
      duration:1000,
    })
    setTimeout(function(){
      wx.navigateBack({
        delta:1
      })
    },1000)
  },
  changeInput(e){
    this.suggestion_content = (e.detail.value)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})